<template>
  <linkage-form ref="formRef" :formList="formList" :formState="formState" @submit="handleSubmit">
  </linkage-form>
</template>

<script setup lang="ts">
const formRef = ref(null)
const formState = reactive({})
const formList = ref([
  {
    label: 'test1',
    name: 'test1',
    type: 'radio',
    props: {
      wrapperCol: { span: 6 },
      rules: [{ required: true, message: '不能为空' }]
    },
    subProps: {
      options: [
        {
          label: 'option1',
          value: 1
        },
        {
          label: 'option1',
          value: 2
        }
      ]
    },
    subEvents: {
      change: (e) => {
        console.log(formRef.value, 111111111)
        formState.type = ''
        formState.tel = ''
      }
    }
  },
  {
    label: '姓名',
    name: 'name',
    type: 'input',
    show: 'test1',
    props: {
      wrapperCol: { span: 6 },
      rules: [{ required: true, message: '不能为空' }]
    },
    subProps: {}
  },
  {
    label: '年龄',
    name: 'age',
    type: 'input',
    show: 'test1',
    props: {
      wrapperCol: { span: 6 },
      rules: [{ required: true, message: '不能为空' }]
    },
    subProps: {}
  },
  {
    label: '联系方式',
    name: 'type',
    type: 'select',
    show: 'test1=2',
    props: {
      wrapperCol: { span: 6 },
      rules: [{ required: true, message: '不能为空' }]
    },
    subProps: {
      options: [
        {
          label: '微信',
          value: 1
        },
        {
          label: '手机号',
          value: 2
        }
      ]
    }
  },
  {
    label: '微信',
    name: 'tel',
    type: 'input',
    show: 'test1=2&type=1',
    props: {
      wrapperCol: { span: 6 },
      rules: [{ required: true, message: '不能为空' }]
    },
    subProps: {}
  },
  {
    label: '手机号',
    name: 'tel',
    type: 'input',
    show: 'test1=2&type=2',
    props: {
      wrapperCol: { span: 6 },
      rules: [{ required: true, message: '不能为空' }]
    },
    subProps: {}
  }
])

const handleSubmit = (data) => {
  console.log(data)
}
</script>

<style scoped>
</style>